package per.zqx.publish_subcribe;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import per.zqx.utils.RabbitUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Publisher
 *
 * @author Sa  2021-03-17 13:51
 */
public class Publisher {
    public static void main(String[] args) throws IOException, TimeoutException {
        String EXCHANGE_NAME = "log_fanout_exchange";
        String QUEUE_NAME = "log_queue";
        try (Connection connection = RabbitUtils.getConnection()) {
            Channel channel = connection.createChannel();
            // 声明一个交换机,类型是分发（fanout）
            channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
            // 声明一个队列
            channel.queueDeclare(QUEUE_NAME, true, false, false, null);
            String msg = "第六套全国中小学广播体操《七彩阳光》，现在开始！";
            // 消息发送给交换机
            channel.basicPublish(EXCHANGE_NAME, "", null,
                    msg.getBytes("utf-8"));
        }
    }
}
